//
//  ZYCConsummateViewController.m
//  ZDSC
//
//  Created by 张威 on 2021/10/12.
//

#import "ZYCConsummateViewController.h"
#import "ZYCProgressOneViewController.h"
#import "ZYCProgressTwoViewController.h"
#import "ZYCProgressThreeViewController.h"
#import "ZYCProgressFourViewController.h"
#import "ZYCProgressFiveViewController.h"
#import "ZYCProgressSixViewController.h"
#import "ZYCConsummateBottomView.h"

@interface ZYCConsummateViewController ()<UIScrollViewDelegate,ZYCConsummateBottomViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIButton *rightButton;
@property (nonatomic, strong) ZYCConsummateBottomView *bottomView;
@end

@implementation ZYCConsummateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightButton];
    [self setupSubView];
    self.view.backgroundColor = HEX_RGB(@"#FAFAFA");
    self.title = @"基本信息 1/6";
    
    // 关闭系统侧滑功能
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

-(BOOL)navigationShouldPopOnBackButton{
    [self judgeIsPopController];
    return NO;
}

//判断是否pop
- (void)judgeIsPopController{
    CGFloat contentX = self.scrollView.contentOffset.x;
    if (contentX == 0) {
        [self.navigationController popViewControllerAnimated:YES];
    }else if (contentX == kScreenWidth) {
        self.title = @"基本信息 1/6";
        [self.scrollView scrollRectToVisible:CGRectMake(0, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomLast;
    }else if (contentX == 2 * kScreenWidth) {
        self.title = @"基本信息 2/6";
        [self.scrollView scrollRectToVisible:CGRectMake(kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
    }else if (contentX == 3 * kScreenWidth) {
        self.title = @"教育背景 3/6";
        [self.scrollView scrollRectToVisible:CGRectMake(2 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
    }else if (contentX == 4 * kScreenWidth) {
        self.title = @"入职资料 4/6";
        [self.scrollView scrollRectToVisible:CGRectMake(3 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
    }else if (contentX == 5 * kScreenWidth) {
        self.title = @"入职资料 5/6";
        [self.scrollView scrollRectToVisible:CGRectMake(4 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
    }
}

- (void)setupSubView{
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.bottomView];
    
    ZYCProgressOneViewController *first = [[ZYCProgressOneViewController alloc] init];
    [self.scrollView addSubview:first.view];
    first.view.frame = CGRectMake(0, 0, kScreenWidth, CGRectGetHeight(self.scrollView.frame));
    [self addChildViewController:first];
    
    ZYCProgressTwoViewController *second = [[ZYCProgressTwoViewController alloc] init];
    [self.scrollView addSubview:second.view];
    second.view.frame = CGRectMake(kScreenWidth, 0, kScreenWidth, CGRectGetHeight(self.scrollView.frame));
    [self addChildViewController:second];
    
    ZYCProgressThreeViewController *third = [[ZYCProgressThreeViewController alloc] init];
    [self.scrollView addSubview:third.view];
    third.view.frame = CGRectMake(2 * kScreenWidth, 0, kScreenWidth, CGRectGetHeight(self.scrollView.frame));
    [self addChildViewController:third];
    
    ZYCProgressFourViewController *four = [[ZYCProgressFourViewController alloc] init];
    [self.scrollView addSubview:four.view];
    four.view.frame = CGRectMake(3 * kScreenWidth, 0, kScreenWidth, CGRectGetHeight(self.scrollView.frame));
    [self addChildViewController:four];
    
    ZYCProgressFiveViewController *five = [[ZYCProgressFiveViewController alloc] init];
    [self.scrollView addSubview:five.view];
    five.view.frame = CGRectMake(4 * kScreenWidth, 0, kScreenWidth, CGRectGetHeight(self.scrollView.frame));
    [self addChildViewController:five];
    
    ZYCProgressSixViewController *six = [[ZYCProgressSixViewController alloc] init];
    [self.scrollView addSubview:six.view];
    six.view.frame = CGRectMake(5 * kScreenWidth, 0, kScreenWidth, CGRectGetHeight(self.scrollView.frame));
    [self addChildViewController:six];
    
}
- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight - 100)];
        _scrollView.contentSize = CGSizeMake(kScreenWidth*6, kScreenHeight - kNavBarAndStatusBarHeight - 100);
        _scrollView.bounces = NO;
        _scrollView.scrollEnabled = NO;
        _scrollView.delegate = self;
    }
    return _scrollView;
}


- (ZYCConsummateBottomView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[ZYCConsummateBottomView alloc] initWithFrame:CGRectMake(0, kScreenHeight - 100, kScreenWidth, 100)];
        _bottomView.delegate = self;
        _bottomView.backgroundColor = HEX_RGB(@"#FAFAFA");
        _bottomView.type = ZYCConsummateBottomLast;
    }
    return _bottomView;
}

- (UIButton *)rightButton {
    if (!_rightButton) {
        _rightButton = [[UIButton alloc] init];
        [_rightButton setTitle:@"提交" forState:UIControlStateNormal];
        [_rightButton setTitleColor:HEX_RGB(@"FFFFFF") forState:UIControlStateNormal];
        [_rightButton addTarget:self action:@selector(clickRightAction:) forControlEvents:UIControlEventTouchUpInside];
        _rightButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 16.0f);
    }
    return _rightButton;
}



#pragma mark - ZYCConsummateBottomViewDelegate
// 上一步
- (void)consummateBottomViewDidLast{
    CGFloat contentX = self.scrollView.contentOffset.x;
    if(contentX ==  kScreenWidth){
        self.title = @"基本信息 1/6";
        [self.scrollView scrollRectToVisible:CGRectMake(0, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomLast;
        
    }else if(contentX == 2 * kScreenWidth){
        self.title = @"基本信息 2/6";
        [self.scrollView scrollRectToVisible:CGRectMake(kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
        
    }else if(contentX == 3 * kScreenWidth){
        self.title = @"教育背景 3/6";
        [self.scrollView scrollRectToVisible:CGRectMake(2 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
        
    }else if(contentX == 4 * kScreenWidth){
        self.title = @"教育背景 4/6";
        [self.scrollView scrollRectToVisible:CGRectMake(3 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
        
    }else if(contentX == 5 * kScreenWidth){
        self.title = @"入职资料 5/6";
        [self.scrollView scrollRectToVisible:CGRectMake(4 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
    }
}
// 下一步
- (void)consummateBottomViewDidNext{
    CGFloat contentX = self.scrollView.contentOffset.x;
    if (contentX == 0) {
        self.title = @"基本信息 2/6";
        [self.scrollView scrollRectToVisible:CGRectMake(kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
    }else if(contentX == kScreenWidth){
        self.title = @"教育背景 3/6";
        [self.scrollView scrollRectToVisible:CGRectMake(2 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
        
    }else if(contentX == 2 * kScreenWidth){
        self.title = @"教育背景 4/6";
        [self.scrollView scrollRectToVisible:CGRectMake(3 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
        
    }else if(contentX == 3 * kScreenWidth){
        self.title = @"入职资料 5/6";
        [self.scrollView scrollRectToVisible:CGRectMake(4 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomDouble;
        
    }else if(contentX == 4 * kScreenWidth){
        self.title = @"入职资料 6/6";
        [self.scrollView scrollRectToVisible:CGRectMake(5 * kScreenWidth, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
        self.bottomView.type = ZYCConsummateBottomNext;
    }
}

- (void)clickRightAction:(UIButton *)sender{
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
